let product_yh_service = {
    // productList.html 分页功能 改变下拉框中每页的记录数时触发
    handleSizeChange: function (val) {
        this.page.pageSize = val;
        vueapp.findAll(this.page.pageNum, val);
    },

    // productList.html 分页功能 点击导航按钮时触发
    handleCurrentChange: function (val) {
        vueapp.findAll(val, this.page.pageSize);
    },

    // itemProductList.html 定义全选功能
    choiceAll: function (checked) {
        // 获取到所有的复选框
        var checks = document.getElementsByName("check");
        // 将所有复选框的状态与全选框保持一致
        for (i=0; i<checks.length; i++) {
            checks[i].checked = checked;
        }
    },

    // addProduct.html 商品图片预览
    show: function (obj) {
        var file = obj.files[0];    // 获取选中的文件
        var fileReader = new FileReader()   // 创建FileReader对象
        fileReader.readAsDataURL(file)  // 开始读取文件
        fileReader.onload = function (ev) {
            var img = document.getElementById("imgId");    // 获取到预览图片的元素
            img.src = ev.target.result;
        }
    },

    // 初始化页面数据
    createdList: function () {
        this.findAll(1,5);
    },
    createdItemList: function () {
        // 从地址中获取商品的id值
        var keys = window.location.href.split("?")[1];
        if (keys != null) {
            // 获取商品ID和默认的单品ID
            var goodsKey = keys.split("&")[0];
            var defaultItemKey = keys.split("&")[1];
            goodsId = goodsKey.split("=")[1];
            this.goodsId = goodsId;
            this.defaultItemId = defaultItemKey.split("=")[1];
            this.findItemFromGoodsId(goodsId,'false');
        } else {
            window.location.href = "productList.html"
        }
    },
    createdDetails: function () {
        // 从地址中获取携带的参数
        var keystr = window.location.href.split("?")[1];
        if (keystr != null) {
            // 获取商品ID(goods)和单品ID(item)和默认的单品ID
            var itemKey = keystr.split("&")[0];
            var goodsKey = keystr.split("&")[1];
            var defaultItemKey = keystr.split("&")[2];
            itemId = itemKey.split("=")[1];
            this.goodsId = goodsKey.split("=")[1];
            this.defaultItemId = defaultItemKey.split("=")[1];
            this.findSpeciAll();
            this.findItemfromId(itemId);
        } else {
            window.location.href = "itemProductList.html"
        }
    },
    createdGoodsDetails: function () {
        // 从地址中获取参数
        var key = window.location.href.split("?")[1];
        var id = null
        if (key != null) {
            id = key.split("=")[1];
            this.findGoodsById(id);
            this.findItemFromGoodsId(id,"true");
        }
        this.findBrandAll();
        this.findSpeciAll();
    },
    createdAdd: function () {
        // 从地址中获取参数
        var key = window.location.href.split("?")[1];
        var id = null
        if (key != null) {
            id = key.split("=")[1];
            this.goodsId = id;
            this.findGoodsById(id);
        }
        this.findBrandAll();
        this.findSpeciAll();
    },
}